//分类全局组件小仓库
import {defineStore} from 'pinia'
//引入一级分类请求方法
import { reqC1 ,reqC2,reqC3} from '@/api/product/attr';
import { ref } from 'vue';
import type {CateproyResponseData,CateproyObj} from '@/api/product/attr/type' 
const useCategroyStore=defineStore('Categroy',()=>{
    //存储一级分类数据
    let c1Arr=ref<CateproyObj[]>([])
    //存储二级分类数据
    let c2Arr=ref<CateproyObj[]>([])
    //存储三级分类数据
    let c3Arr=ref<CateproyObj[]>([])

    //存储一级分类id
    let c1Id=ref<number|string>('')
    //存储二级分类id
    let c2Id=ref<number|string>('')
    //存储三级分类id
    let c3Id=ref<number|string>('')

    //一级分类获取数据
    const getC1=async ()=>{
        const result:CateproyResponseData=await reqC1()
        c1Arr.value=result.data
    }
    //二级分类获取数据
    const getC2=async ()=>{
        const result:CateproyResponseData=await reqC2(c1Id.value)
        c2Arr.value=result.data
    }
    //三级分类获取数据
    const getC3=async ()=>{
        const result:CateproyResponseData=await reqC3(c2Id.value)
        c3Arr.value=result.data
    }

    const $reset=()=>{
        c1Id.value=''
        c2Id.value=''
        c3Id.value=''
        c1Arr.value=[]
        c2Arr.value=[]
        c3Arr.value=[]
    }

    return {getC1,getC2,getC3,c1Arr,c2Arr,c3Arr,c1Id,c2Id,c3Id,$reset}
})

export default useCategroyStore